const mongoose = require('../connect')

const StoreSchema = mongoose.Schema({
  logo: String,
  name: String,
  address: String,
  openTime: String,
  imgList: Array,
  notice: String,
  meta: {
    createdAt: {
      type: Date,
      dafault: Date.now()
    },
    updatedAt: {
      type: Date,
      dafault: Date.now()
    }
  }
});

StoreSchema.pre('save', function (next) {
  if (this.isNew){
    this.meta.createdAt = this.meta.updatedAt = Date.now()
  }else {
    this.meta.updatedAt = Date.now()
  }
  next()
})



const Store = mongoose.model('Store', StoreSchema)

module.exports = Store
